package com.jie.deletefile.Listview.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;

import com.jie.deletefile.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/25 0025.
 */
public class ErshaAdapter extends BaseAdapter {

    private Context context;
    private List<String> datas;

    public ErshaAdapter(Context context, List<String> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHold viewHold;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_ersha, null);
            viewHold = new ViewHold(convertView);
            convertView.setTag(viewHold);
        } else {
            viewHold = (ViewHold) convertView.getTag();
        }
        viewHold.button.setText(datas.get(position));
        List<String> data = new ArrayList<>();
        for (int i=0;i<3;i++) {
            data.add(datas.get(position)+"的傻逼儿子"+i);
        }
        LitAdapter litAdapter = new LitAdapter(context, data);
        viewHold.listView.setAdapter(litAdapter);
        return convertView;
    }

    public static class ViewHold {
        Button button;
        ListView listView;

        public ViewHold() {
        }

        public ViewHold(View view) {
            button = (Button) view.findViewById(R.id.ersha_btn);
            listView = (ListView) view.findViewById(R.id.item_lv);
        }

        public ListView getListView() {
            return listView;
        }
    }

}
